package com.liao.seckill.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lzp
 * @version 1.0
 * lzpnb!
 */

@Configuration
public class RabbitMQConfig {

    private static final String QUEUE = "queue";

    private static final String QUEUE1 = "queue_fanout01";
    private static final String QUEUE2 = "queue_fanout02";
    private static final String EXCHANGE = "fanoutExchange";

    private static final String QUEUE_Direct1 = "queue_direct01";
    private static final String QUEUE_Direct2 = "queue_direct02";
    private static final String EXCHANGE_DIRECT = "directExchange";
    private static final String ROUNTINGKEY01 = "queue.red";
    private static final String ROUNTINGKEY02 = "queue.green";


    @Bean
    public Queue queue() {
        return new Queue(QUEUE, true);
    }

    @Bean
    public Queue queue1() {
        return new Queue(QUEUE1);
    }

    @Bean
    public Queue queue2() {
        return new Queue(QUEUE2);
    }

    @Bean
    public FanoutExchange exchange(){
        return new FanoutExchange(EXCHANGE);
    }

    @Bean
    public Binding binding01() {
        return BindingBuilder.bind(queue1()).to(exchange());
    }


    @Bean
    public Binding binding02() {
        return BindingBuilder.bind(queue2()).to(exchange());
    }

    @Bean
    public Queue queue_direct01() {
        return new Queue(QUEUE_Direct1);
    }

    @Bean
    public Queue queue_direct02() {
        return new Queue(QUEUE_Direct2);
    }

    @Bean
    public DirectExchange exchange_direct(){
        return new DirectExchange(EXCHANGE_DIRECT);
    }

    @Bean
    public Binding binding01_direct() {
        return BindingBuilder.bind(queue_direct01()).to(exchange_direct()).with(ROUNTINGKEY01);
    }

    @Bean
    public Binding binding02_direct() {
        return BindingBuilder.bind(queue_direct02()).to(exchange_direct()).with(ROUNTINGKEY02);
    }

}
